package com.corpgovernment.organization.service;

import com.corpgovernment.api.organization.model.orguserrelation.request.ListUserOrgRelationForLoginRequest;
import com.corpgovernment.api.organization.model.orguserrelation.response.ListUserOrgRelationForLoginResponse;
import com.corpgovernment.api.organization.vo.TransferEmployeeOrgInfoVo;
import com.corpgovernment.organization.dto.ListEmployeeQuery;
import com.corpgovernment.organization.dto.OrgUserInfoPk;
import com.corpgovernment.organization.entity.db.MbOrgEmployeeInfo;
import com.corpgovernment.organization.entity.db.MbUserOrgRelation;
import com.ctrip.corp.obt.shard.sql.mybatis.interceptor.pagination.IPage;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * @author wangyujue
 */
public interface IUserOrgRelationService {

    /**
     * 查询组织结构下用户（手机号，姓名，证件号码匹配）
     *
     * @param listEmployeeQuery
     * @return
     */
    List<MbOrgEmployeeInfo> listByQuery(ListEmployeeQuery listEmployeeQuery, Long roleId);

    IPage<MbOrgEmployeeInfo> listByQueryPage(ListEmployeeQuery listEmployeeQuery, Long roleId, Long jobId);

    List<MbOrgEmployeeInfo> listByQueryAndOgrIds(ListEmployeeQuery listEmployeeQuery, List<String> orgIds, Long roleId);

    IPage<MbOrgEmployeeInfo> listByQueryAndOgrIdsPage(ListEmployeeQuery listEmployeeQuery, List<String> orgIds, Long roleId, Long jobId);

    /**
     * 删除用户身份
     *
     * @param id    用户id
     * @param orgId 组织结构id
     * @return
     */
    boolean delete(String id, String orgId);

    boolean deleteAllByUid(String uid, String orgId);

    /**
     * 批量更新状态
     *
     * @param uids
     * @param orgId
     * @param type
     * @return
     */
    boolean batchUpdateStatus(List<String> uids, String orgId, Integer type);

    /**
     * 查询用户身份
     *
     * @param orgId 组织结构id
     * @param uid   用户id
     * @return 用户身份
     */
    MbUserOrgRelation find(String orgId, String uid);


    List<MbUserOrgRelation> findByUid(String uid);

    List<MbUserOrgRelation> findByUids(List<String> uids);

    /**
     * 批量保存
     *
     * @param needSaveList
     * @return
     */
    boolean batchSave(List<MbUserOrgRelation> needSaveList);

    /**
     * 单个保存
     *
     * @param mbUserOrgRelation
     * @return
     */
    boolean save(MbUserOrgRelation mbUserOrgRelation);

    /**
     * 设置管理员
     *
     * @param orgId 组织结构id
     * @param uids  用户id集合
     * @return
     */
    boolean setUpLeader(String orgId, List<String> uids);

    /**
     * 根据postId清除人员岗位信息
     *
     * @param postId
     * @return
     */
    boolean cleanPostIdByPostId(Long postId);

    /**
     * 根据uid和组织清除人员岗位信息 只删职级关系
     *
     * @param uid
     * @return
     */
    boolean cleanPostIdByUidAndOrgId(String uid, String orgId);


    /**
     * 根据uid和组织设置人员岗位信息
     *
     * @return
     */
    boolean setPostIdByUidAndOrgId(String uid, String orgId, Long postId);

    /**
     * 查询uid的所有身份
     *
     * @param uid 用户id
     * @return 身份列表
     */
    List<MbUserOrgRelation> listByUid(String uid);

    /**
     * 根据uid数组和orgId批量更新岗位
     *
     * @param postId
     * @param uids
     * @param orgId
     * @return
     */
    boolean batchUpdatePostByUidAndOrgId(@Param("postId") Long postId, @Param("uids") List<String> uids, @Param("orgId") String orgId);

    /**
     * 取消负责人
     *
     * @param orgId
     * @param uids
     * @return
     */
    boolean cancelSetUpLeader(String orgId, List<String> uids);

    /**
     * 查询部门负责人
     *
     * @param orgId 组织结构id
     * @return
     */
    List<MbUserOrgRelation> listLeader(String orgId);
    List<MbUserOrgRelation> listAllLeaders();

    /**
     * 根据用户id删除用户
     *
     * @param uid
     */
    boolean deleteByUid(String uid);

    /**
     * 批量清除管理员
     *
     * @param id
     * @param orgId
     * @return
     */
    boolean batchClearLeader(List<String> id, String orgId);

    boolean update(MbUserOrgRelation mbUserOrgRelation);

    /**
     * 根据职级id统计正常用户
     */
    int countNormalUserByPostId(long postId);



    MbUserOrgRelation get(MbUserOrgRelation mbUserOrgRelation);

    List<MbOrgEmployeeInfo> listByPk(List<OrgUserInfoPk> pkList);

    int countEmployee(Integer status, List<String> orgIds);

    List<MbUserOrgRelation> listByUids(List<String> employeeUidList);

    List<MbUserOrgRelation> listByUids();

    List<ListUserOrgRelationForLoginResponse> listUserOrgRelationForLogin(ListUserOrgRelationForLoginRequest request);

    boolean batchUpdateUserOrgRelation(TransferEmployeeOrgInfoVo request);

    boolean deleteUserOrgRelation(TransferEmployeeOrgInfoVo request);

    boolean updatePostIdById(Long postId, Long id);

    boolean deleteByUidAndOrgIdList(List<MbUserOrgRelation> mbUserOrgRelationList);

    boolean insertList(List<MbUserOrgRelation> mbUserOrgRelationList);

    boolean updateByRecord(MbUserOrgRelation record);


}
